import VueRouter from "vue-router";
import Index from "@/views/Index.vue";
// 这里修正登录页点登录报错问题
const originalPush= VueRouter.prototype.push;
// 修改对象的原型中的push方法
VueRouter.prototype.push=function push(location){
    return originalPush.call(this,location).catch((err)=>err);
}
const router=new VueRouter({
    routes:[
        // 首页
        {
            path:"/",
            name:"index",
            component:Index,
        },
         // 手机，电脑，平板产品页
         {
            path:"/product/:id",
            name:"product",
            // 路由懒加载，当我展示对应的路由的时候才加载对应的文件，可以解决首页白屏
            // webpack魔法注释，将来打包的时候会把product组件单独打包成一个js，
            // 去对应的路由才会加载，减轻服务器压力
            component:()=>import(/* webpackChunkName:"product" */"../views/Product.vue")
        },
        // 其他产品页
        {
            path:"/proOne/:id",
            name:"proOne",
            component:()=>import(/* webpackChunkName:"proOne" */"../views/ProOne.vue")
        },
        // 详情页面
        {
            path:"/detail",
            name:"detail",
            component:()=>import(/* webpackChunkName:"detail" */"../views/Detail.vue")
        },
        // 购物车页面
        {
            path:"/cart",
            name:"cart",
            component:()=>import(/* webpackChunkName:"cart" */"../views/Cart.vue")
        },
        // 登录注册
        {
            path:"/login/:n",
            name:"login",
            component:()=>import(/* webpackChunkName:"login" */"../views/Login.vue")
        },
        // 订单页面
        {
            path:"/order",
            name:"order",
            component:()=>import(/* webpackChunkName:"order" */"../views/Order.vue")
        },
         // 我的订单页面
         {
            path:"/myorder",
            name:"myorder",
            component:()=>import(/* webpackChunkName:"myorder" */"../views/MyOrder.vue")
        },
        // 搜索产品页面
        {
            path:"/search",
            name:"search",
            component:()=>import(/* webpackChunkName:"search" */"../views/Search.vue")
        },
    ],
    scrollBehavior (to, from, savedPosition) {
        return { x: 0, y: 0 }
      }
});
export default router;